<!DOCTYPE HTML>
<html lang="en">
<head>
<title>#SingleInstance - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The #SingleInstance directive determines whether a script is allowed to run again when it is already running." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#SingleInstance</h1>

<p>Determines whether a script is allowed to run again when it is already running.</p>

<pre class="Syntax"><span class="func">#SingleInstance</span> <span class="optional">ForceIgnorePromptOff</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>ForceIgnorePromptOff</dt>
  <dd>
    <p>If this parameter is omitted, it defaults to <em>Prompt</em>. To change this behavior, specify one of the following words:</p>
    <p><strong>Force:</strong> Skips the dialog box and replaces the old instance automatically, which is similar in effect to the <a href="Reload.htm">Reload</a> command.</p>  
    <p><strong>Ignore:</strong> Skips the dialog box and leaves the old instance running. In other words, attempts to launch an already-running script are ignored.</p>
    <p><strong>Prompt:</strong> Displays a dialog box asking whether to keep the old instance or replace it with the new one. This is the default behaviour if this directive is not used.</p>
    <p><strong>Off:</strong> Allows multiple instances of the script to run concurrently.</p>
  </dd>

</dl>
<h2>Remarks</h2>
<p>A script containing <a href="../Hotkeys.htm">hotkeys</a>, <a href="../Hotstrings.htm">hotstrings</a>, <a href="_Persistent.htm">#Persistent</a>, <a href="OnMessage.htm">OnMessage()</a>, or <a href="Gui.htm">Gui</a> is single-instance (dialog &amp; prompt) by default. Other scripts default to allowing multiple instances. This behavior can be disabled or modified as described above.</p>
<p>This directive is ignored when any of the following <a href="../Scripts.htm#cmd">command line switches</a> are used: /force /f /restart /r</p>
<p>AutoHotkey relies on the title of the script's <a href="../Program.htm#main-window">main window</a> to identify other running instances of the script.</p>

<h2>Related</h2>
<p><a href="Reload.htm">Reload</a>, <a href="_Persistent.htm">#Persistent</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>#SingleInstance force
#SingleInstance ignore
#SingleInstance off</pre>
</div>

</body>
</html>
